﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QlrrPrintService.Common.Command
{
    public class QRCode : PrintLocation,IToTSPLCommand
    {

        #region fileds

        //    L=0.07,
        //    M=0.15,
        //    Q=0.25,
        //    H=0.30,

        private string _QRCODE_ECC = "L";

        public string QRCODE_ECC
        {
            get { return _QRCODE_ECC; }
            set { _QRCODE_ECC = value; }
        }

        private int _cellWidth = 4;

        public int CellWidth
        {
            get { return _cellWidth; }
            set { _cellWidth = value; }
        }

        /// <summary>
        /// 自動生成編碼/手動生成編碼
        /// A				Auto
		/// M				Manual
        /// </summary>
        private string _mode = "A";

        public string Mode
        {
            get { return _mode; }
            set { _mode = value; }
        }

        /// <summary>
        /// 順時針旋轉角度
        /// 0,90,180,270
        /// </summary>
        private int _rotation = 0;

        public int Rotation
        {
            get { return _rotation; }
            set { _rotation = value; }
        }

        /// <summary>
        /// 條碼生成樣式
        /// </summary>
        private int _model = 1;

        public int Model
        {
            get { return _model; }
            set { _model = value; }
        }

        /// <summary>
        /// 範圍：0~8，預設7
        /// </summary>
        private int _mask = 7;

        public int Mask
        {
            get { return _mask; }
            set { _mask = value; }
        }

        private string _dataString = "";

        public string DataString
        {
            get { return _dataString; }
            set { _dataString = value; }
        }

        #endregion

        #region IToTSPLCommand 成员

        public byte[] ToTSPLCommandByte(int mm_to_dot)
        {
            List<byte> data = new List<byte>();
            
                var c=string.Format("QRCODE {0},{1},{2},{3},{4},{5},",
                _x*mm_to_dot,
                _y*mm_to_dot,
                _QRCODE_ECC.ToString(),
                _cellWidth,
                _mode,
                _rotation);
                
                data.AddRange(System.Text.ASCIIEncoding.UTF8.GetBytes(c));
                data.Add(0x22);
                data.AddRange(System.Text.ASCIIEncoding.UTF8.GetBytes(_dataString));
                data.Add(0x22);
                data.AddRange(System.Text.ASCIIEncoding.UTF8.GetBytes("\r\n"));
            
            return data.ToArray();
        }

        public string ToTSPLCommandAscii(int mm_to_dot)
        {
            return System.Text.ASCIIEncoding.UTF8.GetString(ToTSPLCommandByte(mm_to_dot)) ;
        }

        #endregion
    }
}
